﻿<!-- Aside Block -->
	<section role="navigation">
		<!-- Header with logo and headline -->
		<header>
			<a href="fixed.html" title="Back to Homepage"></a>
			<h1>DEMO</h1>
		</header>
		
		<!-- User Info -->
		<section id="user-info">
			<img src="img/sample_user.png" alt="Sample User Avatar">
			<div>
				<a href="#" title="Account Settings and Profile Page">Albert Ling</a>
				<em>Administrator</em>
				<ul>
					<li><a class="button-link" href="#">View Profile</a></li>
					<li><a class="button-link" href="#">Logout</a></li>
				</ul>
			</div>
		</section>
		<!-- /User Info -->
		
		<!-- Main Navigation -->
		<?php
			echo "<nav id=\"main-nav\">";
			include('config.php');
				$GLOBALS["SUFFIX"]= $current;
				echo "<ul>";
				$GLOBALS["ID"] =1;											//用来跟踪下拉菜单的ID号
				$layer=1;												//用来跟踪当前菜单的级数
				mysql_select_db("menu");
				$sql = "SELECT *
					FROM `menu`
					WHERE `menutype` = 'mainmenu'
					AND `published` =1
					AND `parent` =0
					ORDER BY  `ordering` ASC
					LIMIT 0 , 30";											//提取一级菜单
				$sub_sql = "SELECT *
					FROM `menu`
					WHERE `menutype` = 'mainmenu'
					AND `published` =1
					AND `parent` !=0
					ORDER BY  `ordering` ASC
					LIMIT 0 , 30";										//提取二级菜单
				$result = mysql_query($sql,$connection);
				
				if(mysql_num_rows($result)>0) ShowTreeMenu($connection,$result,$ID,$current);					//如果一级菜单存在则开始菜单的显示
				
				function ShowTreeMenu($connection,$result,$layer,$current)
				{	
					
					$numrows=mysql_num_rows($result);								//取得需要显示的菜单的项目数
					
					for($rows=0;$rows<$numrows;$rows++)
					{
						$menu=mysql_fetch_array($result);							//将当前菜单项目的内容导入数组
						$sql=("SELECT * FROM menu WHERE parent=$menu[id] ORDER BY  `ordering` ASC");					//提取菜单项目的子菜单记录集
						$result_sub=mysql_query($sql,$connection);

						$active[$menu['id']]='class';
						$active[$current] = 'class="current"';
						if(mysql_num_rows($result_sub)>0)							//如果该菜单项目有子菜单
						{
							$nowid = $menu['id'];
							echo "<li ".$active[$nowid]."><a href=". $menu['link'] ." title='' ".$menu['params'].">". $menu['name'] ."</a>";			//输出有子菜单的主菜单
							echo "<ul>";
							while($row = mysql_fetch_array($result_sub))					//子菜单回圈
							{
									echo "<li><a href=". $row['link'] .">". $row['name'] ."</a></li>";
							}
							echo "</li>";
							echo "</ul>";

						}else{
							$nowid = $menu['id'];
							echo "<li ".$active[$nowid]."><a href=". $menu['link'] ." title='' ".$menu['params'].">" . $menu['name'] . "</a></li>";	//如果该菜单项目没有子菜单，只显示菜单名称
						}
					}
				}
			echo "</ul></nav>";
				
		?>
		<!--
		<nav id="main-nav">
			<ul>
				<li  class="current"><a href="fixed.html" title="" class="dashboard no-submenu">Dashboard</a></li> <!-- Use class .no-submenu to open link instead of a sub menu-->
				<!-- Use class .current to open submenu on page load --
				<li>
					<a href="#" title="" class="projects">Order</a>
					<ul>
						<li class="current"><a href="order.php" title="">New Order</a></li>
						<li><a href="#" title="">Edit Order</a></li>
						<li><a href="#" title=""><a href="order-list.php" title="">Order List</a></li>
					</ul>
				</li>
				<li>
					<a href="#" title="" class="products">Products</a>
					<ul>
						<li><a href="#" title="">Add Product</a></li>
						<li><a href="#" title="">Edit Product</a></li>
						<li><a href="#" title="">Product Management</a></li>
					</ul>
				</li>
				<li>
					<a href="#" title="" class="events">Events</a>
					<ul>
						<li><a href="#" title="">My Events</a></li>
						<li><a href="#" title="">Add Event</a></li>
						<li><a href="#" title="">Edit Event</a></li>
						<li><a href="#" title="">Event Management</a></li>
						<li><a href="#" title="">Settings</a></li>
					</ul>
				</li>
				<li><a href="#" title="" class="articles">Order</a><span title="You have 3 new tasks">3</span></li>
				<li><a href="#" title="" class="articles">Undone</a><span title="You have 3 new tasks">3</span></li>
				<li><a href="#" title="" class="gallery">Image Gallery</a><span title="You have 47 new tasks">47</span></li>
				<li><a href="#" title="" class="settings">Settings</a></li>
			</ul>
		</nav>
		<!-- /Main Navigation -->

	</section>
	<!-- /Aside Block -->